import Vue from 'vue'
import Vuex from 'vuex'
import axios from "../axios/index"
import api from "../api/index"
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:'',
    ldata:{}

  },
  mutations: {
    logintoken(state,payload){
      state.token=payload
      window.localStorage.setItem("token",payload)
    },
    logindata(state,payload){
      state.ldata=payload
      window.localStorage.setItem("token",payload)
    }
  },
  actions: {
    Login(context,data){
      return new Promise((resolve,reject)=>{
        console.log(api.login(data));
        
        api.login(data).then(res=>{
          console.log(res);
        if(res.code===1){
          context.commit("logintoken",res.data.token)
        context.commit("logindata",res.data.data)
        resolve(res.data)
        }else{
          reject(res.message)
        }
      }).catch(err=>{
        reject(err)
      })
      
      })
    }
  },
  modules: {
  }
})
